<template>
  <el-card shadow="always" :body-style="{ padding: '15px' }">
    <!-- card body -->
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select
          v-model="categoryStore.c1Id"
          placeholder="请选择"
          @change="c1Handler"
          :disabled="scene==1"
        >
          <el-option
            :label="c1.name"
            :value="c1.id"
            v-for="(c1, index) in categoryStore.c1List"
            :key="c1.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select
          v-model="categoryStore.c2Id"
          placeholder="请选择"
          @change="c2Handler"
          :disabled="scene==1"
        >
          <el-option
            :label="c2.name"
            :value="c2.id"
            v-for="(c2, index) in categoryStore.c2List"
            :key="c2.id"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类">
        <el-select v-model="categoryStore.c3Id" placeholder="请选择" :disabled="scene==1">
          <el-option
            :label="c3.name"
            :value="c3.id"
            v-for="(c3, index) in categoryStore.c3List"
            :key="c3.id"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup lang="ts">
// 引入仓库
import useCategoryStore from "@/stores/category";
import { onMounted } from "vue";
let categoryStore = useCategoryStore();
// 组件挂载时获取一级分类的数据
onMounted(() => {
  categoryStore.getC1List();
});

// 一级分类的id改变时获取二级分类
const c1Handler = () => {
  categoryStore.getC2List();
};
// 二级分类的id改变时获取三级分类
const c2Handler = () => {
  categoryStore.getC3List();
};
defineProps(['scene'])
</script>

<style scoped>
</style>